package com.aqie.easy.binaryTree;

import com.aqie.easy.structure.TreeNode;

/**
 * 100 相同的树
 */
public class IsSameTree {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) return true;
        if (p == null || q == null) return false;

        if (p.val != q.val) return false;
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);

    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.right = null;
        root.left = new TreeNode(2);

        TreeNode root2 = new TreeNode(1);
        root.left = null;
        root.right = new TreeNode(2);
        System.out.println(new IsSameTree().isSameTree(root, root2));
    }
}
